#include "MF.hpp"
#include <iostream>

MF::~MF() {
  UF *current = UF_list;
  while (current) {
    UF *next = current->next_UF;
    delete current;
    current = next;
  }
}

void MF::deleteFile(std::string file_name) {
  UF *current = UF_list;
  UF *prev = nullptr;
  while (current) {
    if (current->file_model.name == file_name) {
      if (prev) {
        prev->next_UF = current->next_UF;
      } else {
        UF_list = current->next_UF;
      }
      delete current;
      return;
    }
    prev = current;
    current = current->next_UF;
  }
  std::cout << "File not found!" << std::endl;
}

UF *MF::findFile(std::string file_name) {
  UF *current = UF_list;
  while (current) {
    if (current->file_model.name == file_name) {
      return current;
    }
    current = current->next_UF;
  }
  return nullptr;
}
